/**********************************************************************************************/
/* FBL_DatabaseManager.h                                                   					  */
/*                                                                       					  */
/* Copyright Paradigma, 1993-2006															  */
/* All Rights Reserved                                                   					  */
/**********************************************************************************************/

#ifndef _FBL_DatabaseManager_h
	#define _FBL_DatabaseManager_h
#pragma once

#include <VShared/FBL/publ/Interfaces/FBL_I_Database.h>


/**********************************************************************************************/
FBL_Begin_Namespace


/**********************************************************************************************/
// This is singleton which keeps references to the databases.
// ( As kernel-dll's dbs so VClient-dll dbs )
//
class FBL_SHARED_EXP_CLASS DatabaseManager
{
	protected://////////////////////////////////////////////////////////////////////////////////
	
							DatabaseManager();
							
	public://///////////////////////////////////////////////////////////////////////////////////
	
							// Access to singleton.
static DatabaseManager* 	get_DatabaseManager( void ) throw();
			
		ulong				get_DatabaseCount( void ) throw();

		I_Database*			get_Database( ulong inIndex ) throw();
		I_Database*			get_Database( const UChar* inName ) throw();
		I_Database*			get_MasterDb( void ) throw();

		ulong				FindIndex(I_Database* inDB ) throw();

	ArrayOfDatabases_Ptr 	get_Databases( void ) throw() { return mDatabases; }


	public://///////////////////////////////////////////////////////////////////////////////////
	
							// This method is for cleanup purpose. 
							// Must be called from ValentinaShutDown() .
		void				Destroy_Databases( bool inIsRemoteOnly ) throw();

		void				RegisterDatabase( I_Database* inDB ) throw();
		void				UnRegisterDatabase( I_Database* inDB ) throw();

		
	private:////////////////////////////////////////////////////////////////////////////////////

static	DatabaseManager*	mInstance;

								// This is array of just I_Database*, i.e. this is not smart 
								// pointers. We need this because we want be that Database object 
								// get destroyed when the last smart pointer of become ZERO. 
								// So we cannot keep in this array smart ptrs, because they will 
								// keep objects forever.

	ArrayOfDatabases_Ptr 	mDatabases;
};


/**********************************************************************************************/
FBL_End_Namespace

#endif // _FBL_DatabaseManager_h
